package com.xkdx.caipiao.presistence.quert;

import java.util.ArrayList;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xkdx.caipiao.module.network.AbsModule;
import com.xkdx.caipiao.pubclass.FirstTitleQueryInfo;
import com.xkdx.caipiao.pubclass.FirstTitleQueryItem;

public class TypeQueryModule extends AbsModule {
	public TypeQueryInfo typeQueryInfo;
	public FirstTitleQueryInfo firstTitleQueryInfo;

	@Override
	public void parseData() throws Exception {
		try {
			backJson = (JSONArray) result;
			for (int i = 0; i < backJson.size(); i++) {
				jsonObj = (JSONObject) backJson.get(i);
				String sortOfAct = jsonObj.getString("Act");
				if (sortOfAct.equals("firstPageList")) {
					parseFirstQuery(jsonObj.getJSONArray("DetailInfo"));
				} else if (sortOfAct.equals("TypeQuery")) {
					parseTypeQuery(jsonObj.getJSONArray("DetailInfo"));
				}

			}
		} catch (Exception e) {
			// to do define a exception include all parseException
			throw e;
		}

	}

	private void parseFirstQuery(JSONArray jsonArray) throws Exception {
		try {
			firstTitleQueryInfo = new FirstTitleQueryInfo();
			List<FirstTitleQueryItem> list = new ArrayList<FirstTitleQueryItem>();
			for (int i = 0; i < jsonArray.size(); i++) {
				JSONObject obj = jsonArray.getJSONObject(i);
				FirstTitleQueryItem info = new FirstTitleQueryItem();
				info.setAdmin(obj.getString("admin"));
				info.setContent(obj.getString("content"));
				info.setCtime(obj.getString("ctime"));
				info.setDevicetype(obj.getString("devicetype"));
				info.setEndtime(obj.getString("endtime"));
				info.setId(obj.getString("id"));
				info.setNum(obj.getString("num"));
				info.setRadmin(obj.getString("radmin"));
				info.setRtime(obj.getString("rtime"));
				info.setStarttime(obj.getString("starttime"));
				info.setStatus(obj.getString("status"));
				info.setTitle(obj.getString("title"));
				list.add(info);
			}

			firstTitleQueryInfo.setList(list);
		} catch (Exception e) {
			throw e;
		}
	}

	private void parseTypeQuery(JSONArray array) throws Exception {
		try {
			typeQueryInfo = new TypeQueryInfo();
			List<TypeQueryItemInfo> list = new ArrayList<TypeQueryItemInfo>();
			for (int i = 0; i < array.size(); i++) {
				JSONObject obj = array.getJSONObject(i);
				TypeQueryItemInfo info = new TypeQueryItemInfo();
				info.setDesc(obj.getString(TypeQueryItemInfo.DESC));
				info.setIcon(obj.getString(TypeQueryItemInfo.ICON));
				info.setIssueid(obj.getString(TypeQueryItemInfo.ISSUEID));
				info.setLotteryid(obj.getString(TypeQueryItemInfo.LOTTERYID));
				info.setOpenawardtime(obj
						.getString(TypeQueryItemInfo.OPENAWARDTIME));
				info.setPool(obj.getString(TypeQueryItemInfo.POOL));
				list.add(info);
			}

			typeQueryInfo.setList(list);
		} catch (Exception e) {
			throw e;
		}
	}

}
